import {Navigate, useRoutes} from "react-router-dom";

import React from "react";

import Login from "@/views/login/Login";
import Main from "@/views/main/Main";
import Home from "@/views/home/Home";
import Article from "@/views/article/Article";
import ArticleList from "@/views/articlelist/ArticleList";
import Content from "@/views/main/Content";
import Comments from "@/views/comments/Comments";
import Messages from "@/views/messages/Messages";
import ArticleListEdit from "@/views/articlelist/ArticleListEdit/ArticleListEdit";


export const routerItem = [
    //重定向到某个页面
    // { path: "/", element: <Navigate to="/mian" /> },
    {path: "/", element: <Login/>, name: "登录"},
    {path: "/login", element: <Navigate to="/"/>},
    {
        path: "/main",
        element: <Main/>,
        name: "布局",
        children: [
            {
                path: "/main/home",
                name: "主页",
                element: <Home/>,
            },
            {
                path: "/main/article",
                name: "文章管理 ",
                element: <Content/>,
                children: [
                    {
                        path: "/main/article/articles",
                        name: "发布文章",
                        element: <Article/>,
                    },
                    {
                        path: "/main/article/article-list",
                        name: "文章列表",
                        element: <ArticleList/>,
                    },

                ]
            },
            {
                path: "/main/message-submenu",
                name: "消息管理",
                element: <Content/>,
                children: [
                    {
                        path: "/main/message-submenu/comments",
                        name: "评论管理",
                        element: <Comments/>,
                    },
                    {
                        path: "/main/message-submenu/messages",
                        name: "留言管理",
                        element: <Messages/>,
                    }
                ]
            }
        ]
    },
    {
        path: "/main",
        element: <Main/>,
        name: "布局",
        children: [
            {
                path: "/main/article/article-edit",
                name: "编辑",
                element: <ArticleListEdit/>,
            }
        ]
    }
]

export const Router = () => {
    const routes: React.ReactElement | null = useRoutes(routerItem);

    return routes;
}
